package com.city.parking.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import android.util.Log;

public class Utils {
	private static final String TAG = "Parking";
	private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
	private static final DecimalFormat df = new DecimalFormat("#.00"); 

	public static void log(String info) {
	    Log.i(TAG, info);
	}

    public static String getCurrentTime() {
        String currentTime = sdf.format(new Date(System.currentTimeMillis()));
        return currentTime;
    }

    public static String getFormatNumber(double num) {
    	return df.format(num);
    }

    public static String getFormatTime(long time) {
    	return sdf.format(new Date(time));
    }
    
    public static long getTime(String fmt) {
    	try {
			return sdf.parse(fmt).getTime();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return 0;
    }

    public static String md5(byte[] source) {
        String s = null;
        char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(source);
            byte tmp[] = md.digest();
            char str[] = new char[16 * 2];
            int k = 0;
            for (int i = 0; i < 16; i++) {
                byte byte0 = tmp[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            s = new String(str);
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return s;
    }
    
    public static boolean isEmptyText(String txt) {
        return txt == null || txt.isEmpty();
    }
}
